/*
 * @Descripttion: |
 * @version: 1.0
 * @Author: 王娆
 * @Date: 2020-08-27 17:21:12
 * @LastEditors: 王娆
 * @LastEditTime: 2020-08-27 17:37:07
 */
/* eslint-disable */
import { Message } from 'element-ui';
import { getExamList } from "../../api/exam/index"
import { getExamType } from "../../api/exam/index"
import { getSubject } from "../../api/exam/index"
import { getCondition } from "../../api/exam/index"
import { getExamDetail } from "../../api/exam/index"
import { postExamAdd } from "../../api/exam/index"
import router from "../../router/index"
const state = {
  count: 'Afsfdsd333',
  examlist: [],
  ExamType: {},
  Subject: {},
  Condition: {},
  ExamDetail: {},
  ExamAdd: {}
}

const mutations = {
  getExamListAll(state,res){
    state.examlist = res.exam

  },
  getExamTypeAll(state,res){
    state.ExamType = res
  },
  getSubjectAll(state,res){
    state.Subject = res
  },
  getConditionAll(state,res){
    state.Condition = res
    state.examlist = res.data
  },
  getExamDetailAll(state,res){
    state.ExamDetail = res.data
  },
  postExamAddAll(state,res){
    state.ExamAdd = res.data
  }
}

const actions = {
  async getExam({ commit }) {
    const { data: res } = await getExamList()
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    commit('getExamListAll',res)
    console.log(res)
  },
  async getExamType({ commit }) {
    const { data: res } = await getExamType()
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    commit('getExamTypeAll',res)
  },
  async getSubject({ commit }) {
    const { data: res } = await getSubject()
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    commit('getSubjectAll',res)
  },
  async getCondition({ commit, state }) {
    const { data: res } = await getCondition(state.Condition)
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    commit('getConditionAll',res)
  },
  async getExamDetail({ commit }, id) {
    const { data: res } = await getExamDetail(id)
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    commit('getExamDetailAll',res)
    router.push('/home/exammanage/exam/detail')
  },
  async postExamAdd({ commit }, params) {
    const { data: res } = await postExamAdd(params)
    if (res.code !== 1) {
      Message.error(res.msg)
    }
    console.log(res)
    router.push('/home/exammanage/exam/edit')
    commit('postExamAddAll',res)
  }
}

export default { state, mutations, actions }